package com.qsmx.core.webfile;

import android.webkit.JavascriptInterface;

import com.alibaba.fastjson.JSON;
import com.qsmx.core.webfile.event.Event;
import com.qsmx.core.webfile.event.EventManager;

/**
 * @ClassName: LatteWebInterface
 * @Description: java类作用描述
 * @Author: Jove.Nan
 * @Date: 2019/3/22 3:06 PM
 */
public final class AtmosWebInterface {
    public WebDelegate DELEGATE;
    public boolean isHasNoTitle;
    private String mUniqueId;
    private String rewardPosition;

    private AtmosWebInterface(WebDelegate delegate, boolean isHasNoTitle) {
        this.DELEGATE = delegate;
        this.isHasNoTitle = isHasNoTitle;
    }

    public static AtmosWebInterface create(WebDelegate delegate, boolean isHasNoTitle) {
        return new AtmosWebInterface(delegate, isHasNoTitle);
    }

    @SuppressWarnings("unused")
    @JavascriptInterface
    public String event(String params) {
        final String action = JSON.parseObject(params).getString("action");
        final Event event = EventManager.getInstance().createEvent(action);
        if (event != null) {
            event.setAction(action);
            event.setDelegate(DELEGATE);
            event.setContext(DELEGATE.getContext());
            event.setUrl(DELEGATE.getUrl());
            event.setWebView(DELEGATE.getWebView());
            return event.execute(params);
        }
        return null;
    }
//    @JavascriptInterface
//    public void downLoadApk(String url, String version) {
//        DownloadUtil.DownLoadMiaoTaiFile(DELEGATE.getContext(), url, version);
//    }
}
